package 剑指Offer.hard;

public class 整数中1出现的次数 {
    static class Solution {
        public static int countDigitOne(int n) {
            int count = 0;
            for (int num = 0; num <= n; num++) {
                int copy = num;
                while (copy > 0) {
                    if (copy % 10 == 1) count++;
                    copy = copy / 10;
                }
            }
            return count;
        }

        public static void main(String[] args) {
            System.out.println(Solution.countDigitOne(12));//5
            System.out.println(Solution.countDigitOne(13));//6
        }
    }
}
